/**
 * Created by dale on 2017/10/9.
 */
$(document).ready(function () {


    var form = new xhForm($('#xh_form'));
    form.parse();
    // $(".form-date").datetimepicker({format: 'yyyy-mm-dd hh:ii', language: 'zh-CN', minView: "hour", autoclose: true});
    $("[name=tStartTime]").datetimepicker({format: 'yyyy-mm-dd hh:ii', language: 'zh-CN', minView: "hour", autoclose: true}).on('changeDate',function(ev){
        var  startTime=$("[name=tStartTime]").val();
        $("[name=tEndTime]").datetimepicker('setStartDate',startTime);
        $.ajax({
            url:baseUrl+'lm/mroom/mrEnum',
            data:{startTime:startTime},
            type:'POST',
            dataType:'json',
            success:function (data) {
                var dom=$('[name=iMeetingRoom]');
                dom.empty();
                var str='<option value="" style="display: none" selected>请选择</option>';
                $.each(data,function (id,text) {
                    str+='<option value="'+id+'">'+text+'</option>';
                })
                dom.append(str);
            },
            error:function (data) {
                window.top.swal(
                    data['responseText'],
                    '',
                    'error'
                );
            }
        });
    });
    $("[name=tEndTime]").datetimepicker({format: 'yyyy-mm-dd hh:ii', language: 'zh-CN', minView: "hour", autoclose: true});
    if(mrInfo!=1){
        if(mrInfo['iState']==2){
            $('.xh-area-form table').append('<tr> <td><label>办公室意见</label></td> <td colspan="3"><textarea name="mOfficeIdea" type="text" rows="2" class="form-control"></textarea></td> </tr>');
        }
        form.fill(mrInfo);
    }
    form.bindRequired($('#bt_modal_confirm',parent.document));

    $('#bt_modal_confirm',parent.document).click(function () {
        $.ajax({
            url:baseUrl+'lm/mroom/saveUseMR',
            data:$('#xh_form').serialize(),
            type:'POST',
            success:function (data) {
                $('#bt_modal_confirm',parent.document).addClass('disabled');
                window.top.xhTop.closeModal();
                window.top.xhTop.getActiveFrame().useMRList.datagrid('reload');
            },
            error:function (data) {
                window.top.swal(
                    data['responseText'],
                    '',
                    'error'
                );
            }
        });
    });


    // modalBind.bindClick();

});